<template>
	<view class="pd pt60 pm120">
		<view class="formrow " @tap="carInputClick">
			<view class="z9 fz28">
				车牌号
			</view>
			<view class="mt20 pr jhhgerttyt row">
			
				<view class="col ml30 fz40 cf">
					{{carform.license_full}}
				</view>
			</view>				
		</view>
		<plate-number ref="plate" v-model="carform.license_full" @showOrHide="showOrHide"></plate-number>
		<view class="formrow mt70">
			<view class="z9 fz28">
				车型
			</view>
			<navigator url='/pages/AddVhicle/index' class="mt20 pr jhhgerttyt row">
				<view class="col">
				<!-- <text class="z9 ">请选择地区</text> -->
				<text v-if="carbrand.brands">
						{{carbrand.model}}-{{carbrand.series}}
				</text>	
				<text class="z9 " v-else>
					请选择车型
				</text>
				</view>
				<!-- <uni-icons type="right" color="#fff" size="16" class="mr10"></uni-icons> -->
				<uni-icons type="right" color="#fff" size="16" class="mr10"></uni-icons>
			</navigator>
		</view>
		<view class="formrow mt70">
			<view class="z9 fz28">
				产品序列号
			</view>
			<view class="pr mt20">
				<input type="text" maxlength="34" value="" placeholder="请输入产品序列号" class="jhhgerttyt mt20" v-model="carform.serial" @input="checklength"/>
				<image src="../../static/img/saoyisao.png" class="saomhnseer" @tap="saomasd"></image>
			</view>
		</view>
		
		
		<view class="formrow mt70">
			<view class="z9 fz28">
				车架号（选填）
			</view>
			<view class="mt20 pr  ">
				<input type="text" value="" class="jhhgerttyt" placeholder="请输入" v-model="carform.vin"/>
			</view>
		</view>
		
		<view class="formrow mt70">
			<view class="z9 fz28">
				发动机号（选填）
			</view>
			<view class="mt20 pr  ">
				<input type="text" value="" class="jhhgerttyt" placeholder="请输入" v-model="carform.engine" />
			</view>
		</view>
		
		<view class="formrow mt70">
			<view class="z9 fz28">
				出厂年份（选填）
			</view>
			<view class="mt20 pr jhhgerttyt row z9  ">
				<picker mode="date" @change="jjcerta" class=" w100">
					<text v-if="from.jhhgdfc">{{from.jhhgdfc}}</text>
					<text v-else class="z9">出厂年份 </text>
					<image src="../../static/img/AddViceKey/kjjhfb.png" class="drrtsert ab" mode="widthFix"></image>
				</picker>
		
			</view>
		</view>		
	</view>
</template>
<script>
	import plateNumber from '@/components/plate-number/plateNumber.vue'
	export default {
		data() {
			return {				
				index: 0,
				array: ['新宝骏-新宝骏RS-3-2020款', '新宝骏-新宝骏RS-3-2020款2', '新宝骏-新宝骏RS-3-2020款3'],
				from:{
					jhhgdfc:''
				},				
				province:['京','冀','晋','蒙','辽','吉','黑','沪','苏','浙','皖','闽','赣','鲁','豫','鄂','湘','粤','桂','琼','渝','川','黔','滇'],
				indexs:0,
				carform:{
					// license_head:"",
					license_full:"",
					model:"",
					serial:"",
					vin:"",
					engine:"",
					year:""
				},
				carbrand:{
					brands:'',
					model:'',
					series:''
				}
			}
		},
		components: {
			plateNumber
		},
		onNavigationBarButtonTap(e) {
			// if (!this.carform.license_head) {
			// 	this.carform.license_head=this.province[0]
			// }
			if (!this.carform.model) {
				this.carform.model=this.array[0]
			}
			if (!this.carform.license_full) {
				uni.showToast({
					icon: "none",
					title: '请输入车牌号'
				})
				return
			}
			if (!this.carform.serial) {
				uni.showToast({
					icon: "none",
					title: '请输入产品序列号'
				})
				return
			}
			if(this.carform.serial.length !=34){
				uni.showToast({
					icon: "none",
					title: '产品序列号输入不正确'
				})
				return
			}
			
			if (!this.from.model) {
				uni.showToast({
					icon: "none",
					title: '请选择车型'
				})
				return
			}
			// uni.setStorageSync('carform',this.carform)
			var carform = JSON.stringify(this.carform)
			uni.navigateTo({
				url:'UploadPictures?data='+carform
			})
			// uni.$emit("carform", {
			// 	carform:that.carform
			// });
		},
		methods: {
			showOrHide(falg) {
			    this.isCursor = falg;
			},
			carInputClick() {
			    this.$refs.plate.show();
			},
			saomasd(){
				let that =this
				uni.scanCode({
				    success: function (res) {
						that.carform.serial = res.result
				    }
				});
			},
			bindPickerChange(e) {
				this.index = e.detail.value
				this.carform.model=this.array[e.detail.value]
			},
			jjcerta(e) {
				this.from.jhhgdfc = e.detail.value
				this.carform.year=e.detail.value
			},
			async cartype(){
				var param={}
				var car=await this.get('/api/brands',param)
				console.log("data",car)
				this.carList=car.data
			},
			bindPickerChangeProvince(e){
				this.indexs = e.detail.value
				this.carform.license_head=this.province[e.detail.value]
			}
			// jump(){	
			// 	console.log("555"+this.carform)
			// 	uni.navigateTo({
			// 		url:'UploadPictures?carform=' + encodeURIComponent(JSON.stringify(this.carform))
			// 	})
			// }
		},		
		onLoad() {	
			uni.$on('carbrand',(params)=>{
			        if(params.type == 1){
						this.carbrand.brands =  params.name
					}else if(params.type == 2){
						this.carbrand.series =  params.name
					}else{
						this.carbrand.model =  params.name
					}
					this.from.model = this.carbrand.brands+this.carbrand.series+this.carbrand.model
			    
			    console.log(this.from.model);
			    console.log(this.carbrand);
				})
		},
		onUnload(){
			uni.$off('carbrand')
		},
		mounted() {}
	}
</script>
<style lang='scss' scoped>

</style>
